package com.antler.smt.portal.service.impl;

import com.antler.smt.entity.AttachmentEntity;
import com.antler.smt.entity.MemberEntity;
import com.antler.smt.portal.mapper.AttachmentEntityMapper;
import com.antler.smt.portal.mapper.MemberEntityMapper;
import com.antler.smt.response.base.Result;
import com.antler.smt.response.portal.GetImgResp;
import com.antler.smt.service.portal.MemberImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *  会员头像操作
 *
 * @author zhangyi
 * @date 2018/5/14 9:27
 */
@Service
public class MemberImgServiceImpl implements MemberImgService {

    @Autowired
    private AttachmentEntityMapper attachmentEntityMapper;

    @Autowired
    private MemberEntityMapper memberEntityMapper;

    /**
     *  获取会员头像信息
     *
     * @param memberId
     * @return
     */
    @Override
    public Result<GetImgResp> getImgInfo(Long memberId) {
        Result result = null;

        MemberEntity memberEntity =
                memberEntityMapper.selectByPrimaryKey(memberId);
        AttachmentEntity attachmentEntity =
                attachmentEntityMapper.selectByPrimaryKey(memberEntity.getHeadImageAttachmentId());

        GetImgResp imgResp = new GetImgResp();
        if(attachmentEntity != null){
            imgResp.setImgName(attachmentEntity.getFileName());
        }
        result = new Result(imgResp);

        return result;
    }
}
